<!-- 
说明：列表
作者：刘永盛 
日期：2018-6-23 21:33:4 
版本：1.0.0
-->
<template>
  <el-dialog :title="title || '管理文件夹'"
             visible
             lock-scroll
             :before-close="handleClose"
             width="600px">
    <mk-search-box>
      <el-row>
        <el-col :span="12">
          <label>文件夹名称:</label>
          <el-input v-model="ui.searchData.cfname"
                    size="small"></el-input>
        </el-col>
        <el-col :span="12">
          <mk-search-buttons v-model="ui.searching" />
        </el-col>
      </el-row>
    </mk-search-box>
    <el-row>
      <add @reload="doSearch"
           :rstype="rstype" />
    </el-row>
    <mk-table v-model="ui"
              mk-index
              height="400"
              mk-sql-code="cmResourceFolder.select_list"
              mk-table-id="cm-resource-folder.list.common"
              :mk-init-search-data="initSearchData"
              ref="table">
      <el-table-column align="left"
                       prop="cfname"
                       label="文件夹名称" />
      <el-table-column align="left"
                       prop="rstype"
                       label="资源类别"
                       width="100" />
      <el-table-column prop="doing"
                       align="center"
                       label="操作"
                       width="120">
        <template slot-scope="scope">
          <edit :row="scope.row"
                @reload="doSearch" />
          <mk-button :type="4"
                     @click="deleteFolder(scope.row)"
                     confirm-text="确定要删除么？">删除</mk-button>
        </template>
      </el-table-column>
    </mk-table>
  </el-dialog>
</template>

<script>
import { MkBase } from 'element-ui'
import Add from './list/add-button'
import Edit from './list/edit-button'
import searchData from './list/search-data'

export default {
  name: 'cm-resource-folder-list',
  mixins: [MkBase],
  components: {
    Add,
    Edit
  },
  props: {
    rstype: String
  },
  data () {
    return {
      ui: {
        searching: true,
        searchData: searchData()
      }
    }
  },
  mounted () {
    this.searchData.rstype = this.rstype
  },
  methods: {
    /**
     * 刷新本页面
     */
    doSearch () {
      this.ui.searching = true
    },
    initSearchData (data, flag) {
      data.rstype = this.rstype
    },
    handleClose () {
      this.$emit('close')
    },
    async deleteFolder (row) {
      let data = await this.$delete('cmResourceFolder/deleteByid.json', {
        cfid: row.cfid
      })
      if (data) {
        this.doSearch()
      }
    }
  }
}
</script>